import java.util.Arrays;
import java.util.Random;

public class Test1 {
    /**
     * 插入排序的调用和插入排序的耗时
     * @param array
     */
    public static void testInsert(int[] array) {
        array=Arrays.copyOf(array,array.length);
        long start=System.currentTimeMillis();
        Test.insertSort(array);
        long end=System.currentTimeMillis();
        System.out.println("插入排序耗时："+(end-start));
    }

    /**
     * 100000个乱序的数组元素
     * @param array
     */
    public static void func1(int[] array){
        Random random=new Random();
            for (int i = 0; i < array.length; i++) {
                array[i]=random.nextInt(10_0000);
            }

    }

    /**
     *100000个有序的数组元素
     * @param array
     */
    public static void func2(int[] array){
        Random random=new Random();
        for (int i = 0; i < array.length; i++) {
            array[i]=i;
        }
    }
    /**
     * 希尔排序
     */
    public static void shellInsert(int[] array) {
        array=Arrays.copyOf(array,array.length);
        long start=System.currentTimeMillis();
        Test.shellSort(array);
        long end=System.currentTimeMillis();
        System.out.println("希尔排序耗时："+(end-start));
    }

    public static void selectSort(int[] array) {
        array=Arrays.copyOf(array,array.length);
        long start=System.currentTimeMillis();
        Test.selectSort(array);
        long end=System.currentTimeMillis();
        System.out.println("选择排序耗时："+(end-start));
    }

    public static void TestHeapSort(int[] array) {
        array=Arrays.copyOf(array,array.length);
        long start=System.currentTimeMillis();
        Test.heapSort(array);
        long end=System.currentTimeMillis();
        System.out.println("堆排序耗时："+(end-start));
    }

    public static void TestbubbleSort(int[] array) {
        array=Arrays.copyOf(array,array.length);
        long start=System.currentTimeMillis();
        Test.bubbleSort(array);
        long end=System.currentTimeMillis();
        System.out.println("冒泡排序耗时："+(end-start));
    }
    public static void TestquickSort(int[] array) {
        array=Arrays.copyOf(array,array.length);
        long start=System.currentTimeMillis();
        Test.quickSort(array);
        long end=System.currentTimeMillis();
        System.out.println("冒泡排序耗时："+(end-start));
    }
    /**
     * 测试排序
     * @param args
     */
    public static void main(String[] args) {
        int[] array=new int[10_0000];
        //插入排序
        func2(array);
        testInsert(array);
        func1(array);
        testInsert(array);
        //希尔排序
        func1(array);
        shellInsert(array);
        func2(array);
        shellInsert(array);
        //选择排序
        func1(array);
        selectSort(array);
        func2(array);
        selectSort(array);
        //堆排序
        func1(array);
        TestHeapSort(array);
        func2(array);
        TestHeapSort(array);
        //冒泡排序
        func1(array);
        TestbubbleSort(array);
        func2(array);
        TestbubbleSort(array);
        //快速排序
        func1(array);
        TestquickSort(array);
        func2(array);
        TestquickSort(array);
    }
}
